import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            redirect: '/home'
        },
        {
            path: '/home',
            name: 'Home',
            component: () => import('@/views/home/HomeIndex.vue'),
            meta: {
                title: '首页',
                show: true
            },
        },
        {
            path: '/category/:id',
            name: 'Category',
            component: () => import('@/views/category/CategoryIndex.vue'),
            meta: {
                title: '分类',
                show: true
            }
        },
        {
            path: '/category/sub/:id',
            name: 'SubCategory',
            component: () => import('@/views/subcategory/SubIndex.vue'),
            meta: {
                title: '子分类',
                show: true
            }
        },
        {
            path: '/detail/:id',
            name: 'Detail',
            component: () => import('@/views/detail/DetailIndex.vue'),
            meta: {
                title: '详情',
                show: true
            }
        },
        {
            path: '/my/cart',
            name: 'CartList',
            component: () => import('@/views/cartlist/CartListView.vue'),
            meta: {
                title: '购物车',
                show: true
            }
        },
        {
            path: '/my/checkout',
            name: 'Checkout',
            component: () => import('@/views/checkout/CheckView.vue'),
            meta: {
                title: '结算',
                show: true
            }
        },
        {
            path: '/my/pay',
            name: 'Pay',
            component: () => import('@/views/pay/PayOrder.vue'),
            meta: {
                title: '支付',
                show: true
            }
        },
        {
            path: '/my/account',
            name: 'MyOrder',
            component: () => import('@/views/order/OrderIndex.vue'),
            meta: {
                title: '我的订单',
                show: true
            },
            children: [
                {
                    path: '/my/account',
                    name: 'UserInfo',
                    component: () => import('@/views/order/components/UserInfo.vue'),
                    meta: {
                        title: '个人中心',
                        show: true
                    }
                },
                {
                    path: '/my/orderList',
                    name: 'OrderList',
                    component: () => import('@/views/order/components/UserOrder.vue'),
                    meta: {
                        title: '订单列表',
                        show: true
                    }
                },
            ]
        },

        {
            path: '/login',
            name: 'Login',
            component: () => import('@/views/login/LoginIndex.vue'),
            meta: {
                title: '登录',
                show: false
            }
        },
        {
            path: '/register',
            name: 'register',
            component: () => import('@/views/Register/RegisterIndex.vue'),
            meta: {
                title: '注册',
                show: false
            }
        },
    ],

    // 路由切换时滚动条位置
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { top: 0, left: 0 }
        }
    }
})

export default router